package com.sanfeng.smbms.controller;

import com.sanfeng.smbms.common.utils.PageUtils;
import com.sanfeng.smbms.common.utils.R;
import com.sanfeng.smbms.entity.OrderEntity;
import com.sanfeng.smbms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author Nelson
 * @email Nelson@gmail.com
 * 订单汇总
 * @date 2022-07-03 17:23:57
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public R listAll() {
        List<OrderEntity> orderEntities = orderService.queryPage();
        return R.ok().put("page", orderEntities);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        OrderEntity order = orderService.getById(id);
        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public R save(@RequestBody OrderEntity order) {
        orderService.save(order);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order) {
        orderService.updateById(order);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List ids) {
        orderService.removeByIds(ids);
        return R.ok();
    }

}
